package edu.hawaii.duedates;
import java.util.Hashtable;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
//import com.meterware.httpunit.WebTable;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
//import static org.junit.Assert.assertNotNull;
//import org.junit.Ignore;

/**
 * Test case for DueDates class.
 * 
 * @author Yasuyuki Kaneshige and Jeho Jung
 */

public class TestDueDates {
  
  private final String testId1 = System.getenv("DUEDATES_TESTUSER1_ID");
  private final String testName1 = System.getenv("DUEDATES_TESTUSER1_LASTNAME");
  private final String testId2 = System.getenv("DUEDATES_TESTUSER2_ID");
  private final String testName2 = System.getenv("DUEDATES_TESTUSER2_LASTNAME");
  
  /**
   * Tests for no books checked out.
   * 
   * @exception Exception if login errors.
   */
  @Test
  public void testNoBooksOut() throws Exception {
    DueDates dueDate = new DueDates();
    Hashtable<String, String> uhInfo = dueDate.getUhInfo(testId1, testName1);
    assertEquals("Testing no books out.", "No items Checked Out", uhInfo.get("No Due Dates"));
  }

  
  /**
   * Tests for books checked out.
   * 
   * @exception Exception if login errors.
   */
  @Test
  public void testBooksOut() throws Exception {
    DueDates dueDate = new DueDates();
    String book01 = "Alexander, Ernest R.  Urban planning : a guide to information sources ...";
    Hashtable<String, String> uhInfo = dueDate.getUhInfo(testId2, testName2);
    try {
       assertTrue("Testing books out.",uhInfo.containsKey(book01));
    }
    catch (Exception e) {
      throw new Exception("Error getting UH Book info", e);
    }   
  }

  
  /**
   * Tests if loginToUhLibrary works.
   * 
   * @exception Exception if login errors.
   */
  @Test
  public void testLogin() throws Exception {
    String id = testId1;
    String lastName = testName1;
    DueDates dueDate = new DueDates();
    WebConversation conversation = dueDate.loginToUhLibrary(id, lastName);
    WebResponse response = conversation.getCurrentPage();
    assertTrue("Testing correct Login Display", response.getText().contains("Checked Out Items"));
  }
  
  
  //public void testGetHawaiiStateInfo() throws Exception {
    //String id = testId1;
    //String lastName = testName1;
    //DueDates dueDate = new DueDates();
    //WebConversation conversation = dueDate.getHawaiiStateInfo(hiStateId, hiStatePassword)
  //}
  
}

  